﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using EPiServer;
using EPiServer.Core;

namespace EPiBoost.Core.Helpers
{
	public static class HttpContextHelper
	{
		public static PageData GetCurrentPageFromHttpContext()
		{
			var page = HttpContext.Current.Handler as PageBase;
			if (page != null)
			{
				return page.CurrentPage;
			}
			else
			{
				var pageRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.Web.Routing.PageRouteHelper>();
				PageData currentPage = pageRouteHelper.Page;
				if (currentPage != null)
				{
					return currentPage;
				}
			}
			return null;
		}
	}
}
